package com.rjs.nio.channel;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class SocketChannelDemo {

	public static void main(String[] args) throws IOException {
		SocketChannel socketChannel = SocketChannel.open();
		socketChannel.connect(new InetSocketAddress("127.0.0.1", 9999));
		
		ByteBuffer buffer = ByteBuffer.allocate(128);
		buffer.put("hello world".getBytes());
		buffer.flip();
		while(buffer.hasRemaining()) {
			socketChannel.write(buffer);
		}
		socketChannel.close();
	}
}
